OPTIONAL DLL-TOOLS.F
\ For SwiftForth

ALSO FORTH DEFINITIONS

Requires Structs

: cstyle:   ( XT -- )
  create , immediate does> @ >r [char] ) parse evaluate r> state @ if compile, else execute then ;
: cstyle   ( -- )
  last @ name>   s" cstyle: " pad place  last @ count pad append s" (" pad append   pad count evaluate ;


: CREATE>$   ( -- addr count ) >IN @ CREATE >IN ! BL WORD COUNT ;

create zbuf 256 allot
: Z$   zbuf zplace zbuf ;

PACKAGE WINDOWS-INTERFACE
PUBLIC

: LIBGLOBAL
   CREATE>$ Z$ FIND-PROC
     0= ABORT" Global not found in library."
     ,   DROP   DOES> @ ;

: VOID  RETURNS-DATA OFF ;


warning @
warning off

: IMPORT: ( n "name" -- )
  C/PASCAL OFF  _IMPORT:  RETURNS-DATA ON  cstyle ;

: CIMPORT: ( n "name" -- )
  DUP C/PASCAL ! _IMPORT:  RETURNS-DATA ON  cstyle ;

: FUNCTION:   FUNCTION:   RETURNS-DATA ON  cstyle ;
: CFUNCTION:   CFUNCTION:   RETURNS-DATA ON  cstyle ;

warning !

returns-data ON


: #DEFINE   create 0 parse evaluate , does> @ ;

: (Proc:) ( n proc -- <name> )
   header
   HERE 13 + DUP >R ,CALL               \ forward call to code compiled by WPCALL
   ( proc ) ,                           \ compile address of proc
   0 ,                                  \ ( void dll pointer )
   ( n ) WPCALL                         \ compile in-line code to make the actual proc call
   R> CODE> ['] .PROC DECODE, ;         \ make a way to decode it

: Proc:
  C/PASCAL OFF  (Proc:)  RETURNS-DATA ON  -? cstyle ;

: CProc:
  C/PASCAL OFF  (Proc:)  RETURNS-DATA ON  -? cstyle ;

END-PACKAGE
